using System;
using UnityEngine;
//using GoogleMobileAds;
//using GoogleMobileAds.Api;
using System.Collections.Generic;
//using StartApp;



// Example script showing how to invoke the Google Mobile Ads Unity plugin.
public class GoogleAdsManager : MonoBehaviour
{

    //public GoogleMobileAds.Editor.GoogleMobileAdsSettings googleMobileAdsSettings;

//    [Space(15)]
//    public string AndroidBannerID;
//    public string AndroidInterstitialID;
//    private string AndroidVideoRewardID;

//    [Space(15)]
//    [Header("Backup Ads")]
//    public string startAppID;
//    //public bool showSplashAds;



//    //public AdPosition BannerPosition;
//    //	[SerializeField]
//    [Space(15)]
//    //public bool ShowBannerOnStart;

//    public int showAfterDie = 3;
//    private int dieCount = 0;

//    public static GoogleAdsManager GoogleAdsManager_instance;


//    BannerAd banner;


//    public static GoogleAdsManager Instance
//    {
//        get
//        {
//            if (GoogleAdsManager_instance == null)
//            {
//                GoogleAdsManager_instance = GameObject.FindObjectOfType<GoogleAdsManager>();
//                DontDestroyOnLoad(GoogleAdsManager_instance.gameObject);
//            }
//            return GoogleAdsManager_instance;
//        }
//    }

//    private BannerView bannerView;
//    private GoogleMobileAds.Api.InterstitialAd interstitial;
//    //private RewardBasedVideoAd rewardBasedVideo;
//    private float deltaTime = 0.0f;
//    private static string outputMessage = string.Empty;

//    public static string OutputMessage
//    {
//        set { outputMessage = value; }
//    }

//    void Awake()
//    {
//        if (GoogleAdsManager_instance == null)
//        {
//            GoogleAdsManager_instance = this;
//            DontDestroyOnLoad(this.gameObject);
//        }
//        else
//        {
//            if (this != GoogleAdsManager_instance)
//                Destroy(this.gameObject);

//            return;
//        }

//        //RequestInterstitial();
//        //RequestBanner();

//    }

//    void Start()
//    {
//        // if (showSplashAds)
//        // {
//        //     AdSdk.Instance.ShowSplash();
//        // }


//#if !UNITY_EDITOR
//        AdSdk.Instance.DisableReturnAds();
//#endif

//        // if (ShowBannerOnStart)
//        //     RequestBanner();
//    }

//    public int getDieCount()
//    {
//        return dieCount;
//    }

//    public void setDieCount(int count)
//    {
//        dieCount = count;
//    }


//    // Returns an ad request with custom ad targeting.
//    private AdRequest CreateAdRequest()
//    {
//        AdRequest request;
//        if (PlayerPrefs.GetInt("npa") == 0)
//        {

//            request = new AdRequest.Builder()
//            .Build();
//        }
//        else
//        {
//            request = new AdRequest.Builder()
//            .AddExtra("npa", "1")
//            .Build();
//        }

//        return request;
//    }

//    public void RequestBanner()
//    {

//        // Create a 320x50 banner at the top of the screen.
//        this.bannerView = new BannerView(AndroidBannerID, AdSize.SmartBanner, AdPosition.Bottom);

//        // Register for ad events.
//        this.bannerView.OnAdLoaded += this.HandleAdLoaded;
//        this.bannerView.OnAdFailedToLoad += this.HandleAdFailedToLoad;
//        this.bannerView.OnAdLoaded += this.HandleAdOpened;
//        this.bannerView.OnAdClosed += this.HandleAdClosed;
//        //this.bannerView.OnAdLeavingApplication += this.HandleAdLeftApplication;

//        // Load a banner ad.
//        this.bannerView.LoadAd(this.CreateAdRequest());
//        this.bannerView.Hide();

//    }

//    public void ShowBanner()
//    {
//        this.bannerView.Show();
//    }

//    public void HideBanner()
//    {
//        this.bannerView.Hide();
//    }

//    public void DestroyBanner()
//    {
//        this.bannerView.Destroy();
//    }

//    public void RequestInterstitial()
//    {


//        // Create an interstitial.
//        this.interstitial = new GoogleMobileAds.Api.InterstitialAd(AndroidInterstitialID);

//        // Register for ad events.
//        this.interstitial.OnAdLoaded += this.HandleInterstitialLoaded;
//        this.interstitial.OnAdFailedToLoad += this.HandleInterstitialFailedToLoad;
//        this.interstitial.OnAdOpening += this.HandleInterstitialOpened;
//        this.interstitial.OnAdClosed += this.HandleInterstitialClosed;
//        this.interstitial.OnAdLeavingApplication += this.HandleInterstitialLeftApplication;

//        // Load an interstitial ad.
//        this.interstitial.LoadAd(this.CreateAdRequest());
//    }

//    public void ShowInterstitial()
//    {
//        if (interstitial.IsLoaded())
//        {
//            interstitial.Show();
//        }
//    }

//    private void LoadStartAppInterstitial()
//    {
//        //#if !UNITY_EDITOR
//        var ad = AdSdk.Instance.CreateInterstitial();
//        ad.RaiseAdLoaded += (sender, e) =>
//        {
//            ad.ShowAd();
//        };
//        //#endif
//        ad.LoadAd(StartApp.InterstitialAd.AdType.Automatic);
//    }

//    private void LoadStartAppBanner()
//    {
//#if !UNITY_EDITOR
//        banner = AdSdk.Instance.CreateBanner();
//        banner.ShowInPosition(BannerAd.BannerPosition.Bottom);
//#endif

//    }


//    private void HideStartAppBanner()
//    {
//        if (banner != null)
//        {
//            banner.Hide();
//        }
//    }



//    // private void RequestRewardBasedVideo()
//    // {
//    //     this.rewardBasedVideo = RewardBasedVideoAd.Instance;

//    //     this.rewardBasedVideo.LoadAd(this.CreateAdRequest(), AndroidVideoRewardID);
//    // }


//    // public bool isVideoReady()
//    // {
//    //     return this.rewardBasedVideo.IsLoaded();
//    // }



//    // public void ShowVideoReward(EventHandler<Reward> handler)
//    // {

//    //     this.rewardBasedVideo.OnAdRewarded += handler;

//    //     if (this.rewardBasedVideo.IsLoaded())
//    //     {
//    //         this.rewardBasedVideo.Show();
//    //     }
//    //     else
//    //     {
//    //         RequestRewardBasedVideo();
//    //     }

//    // }


//    #region Banner callback handlers

//    public void HandleAdLoaded(object sender, EventArgs args)
//    {
//        ShowBanner();
//        // if (ShowBannerOnStart)
//        // {
//        //     ShowBanner();
//        // }
//        //MonoBehaviour.print("HandleAdLoaded event received");
//    }

//    public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
//    {
//        //LoadStartAppBanner();
//        //MonoBehaviour.print("HandleFailedToReceiveAd event received with message: " + args.Message);
//    }

//    public void HandleAdOpened(object sender, EventArgs args)
//    {
//        //MonoBehaviour.print("HandleAdOpened event received");
//    }

//    public void HandleAdClosed(object sender, EventArgs args)
//    {
//        //MonoBehaviour.print("HandleAdClosed event received");
//    }

//    public void HandleAdLeftApplication(object sender, EventArgs args)
//    {
//        //MonoBehaviour.print("HandleAdLeftApplication event received");
//    }

//    #endregion

//    #region Interstitial callback handlers

//    public void HandleInterstitialLoaded(object sender, EventArgs args)
//    {
//        ShowInterstitial();
//        //MonoBehaviour.print("HandleInterstitialLoaded event received");
//    }

//    public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
//    {
//        LoadStartAppInterstitial();
//        //RequestInterstitial();
//        //        MonoBehaviour.print(
//        //            "HandleInterstitialFailedToLoad event received with message: " + args.Message);
//    }

//    public void HandleInterstitialOpened(object sender, EventArgs args)
//    {
//        //MonoBehaviour.print("HandleInterstitialOpened event received");
//    }

//    public void HandleInterstitialClosed(object sender, EventArgs args)
//    {
//        //RequestInterstitial();
//        //MonoBehaviour.print("HandleInterstitialClosed event received");
//    }

//    public void HandleInterstitialLeftApplication(object sender, EventArgs args)
//    {
//        //MonoBehaviour.print("HandleInterstitialLeftApplication event received");
//    }

//    #endregion

}
